package com.mm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class Swagger2 {

    // 访问地址
//	http://localhost:8088/swagger-ui.html
//	http://localhost:8081/doc.html
    // 配置swagger2核心配置
    @Bean
    public Docket createRestApi() {

        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        tokenPar.name("real_source_ip").description("192.168.0.16").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());
        return new Docket(DocumentationType.SWAGGER_2) // 指定api类型为swagger2
                .apiInfo(apiInfo()) // 定义api文档汇总信息
                .select().apis(RequestHandlerSelectors.basePackage("com.mm.controller")) // 扫描Controller包
                .paths(PathSelectors.any())// 所有Controller
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("铭明网络人事管理系统开发接口") // 文档标题
                .contact(new Contact("铭明网络", "www.mmwl7780.com", "guyimeng.hu@qq.com"))// 联系人信息
                .description("铭明网络人事管理系统开发的api文档")// 详细信息
                .version("1.0.0")// 版本号
                .termsOfServiceUrl("www.mmwl7780.com")// 网站地址
                .build();

    }
}
